package sparkstreaming.eighteenthday1.lesson1

import org.apache.spark.streaming.dstream.{DStream, ReceiverInputDStream}
import org.apache.spark.streaming.{Seconds, StreamingContext}
import org.apache.spark.{SparkConf, SparkContext}

object NetWordCount {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local[*]").setAppName(s"${this.getClass.getSimpleName}")
    val sc = new SparkContext(conf)

    val ssc = new StreamingContext(sc, Seconds(5))
    //val ssc = new StreamingContext(conf, Seconds(5))


    val line: ReceiverInputDStream[String] = ssc.socketTextStream("hadoop01", 9999)
    val df: DStream[String] = line.flatMap(_.split(" "))
    val wordOne: DStream[(String, Int)] = df.map((_, 1))

    val wordCount: DStream[(String, Int)] = wordOne.reduceByKey(_+_)

    wordCount.print()

    ssc.start()
    ssc.awaitTermination()
    ssc.stop()
  }
}
